package cc.fs.zhihuapp.ui.activity;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.widget.Toolbar;

import cc.fs.zhihuapp.R;
import cc.fs.zhihuapp.ui.activity.helper.BaseActivity;
import cc.fs.zhihuapp.ui.fragment.DataListFragment;

/**
 * Created by fostion on 2015/9/6.
 */
public class MyActivity extends BaseActivity {

    DataListFragment fragment;
    Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_my_data);
        toolbar = (Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        setupFragment();
    }

    private void setupFragment() {
        //解决fragment bug
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragment = (DataListFragment)fragmentManager.findFragmentByTag(DataListFragment.class.getName());
        if (fragment == null || fragment.isDetached()) {
            fragment = (DataListFragment)Fragment.instantiate(this, DataListFragment.class.getName());
            fragmentTransaction.add(R.id.container, fragment, DataListFragment.class.getName());
        }
        fragmentTransaction.commit();
    }

    @Override
    public void handler(Message msg) {

    }

}
